import { Component, OnInit } from '@angular/core';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/primeng';
import { MdlDialogService, MdlSnackbarService } from '@angular-mdl/core';
import { FreeflowService } from '../freeflow.service';

@Component({
    templateUrl: './ffact-event.component.html',
    styleUrls: ['./ffact-event.component.scss']
})
export class FfActEventComponent implements OnInit {
    actDefId: number;
    events: any[];
    procActEvent: any = {};
    cols: any[] = [
        { field: 'eventId', header: '标识', width: '60px' },
        { field: 'eventTypeName', header: '类型', width: '100px' },
        { field: 'eventName', header: '名称', width: '120px' },
        { field: 'eventClazz', header: '类路径', width: '' }
    ];
    constructor(
        public ref: DynamicDialogRef,
        public config: DynamicDialogConfig,
        private mdlDialogService: MdlDialogService,
        private mdlSnackbarService: MdlSnackbarService,
        private freeflowService: FreeflowService) {
        this.actDefId = this.config.data.actDefId;
    }

    ngOnInit() {
        this.freeflowService.loadProcActEvents(this.actDefId).subscribe(events => this.events = events);
    }

    /** 保存 */
    save() {
        if (this.procActEvent.eventName && this.procActEvent.eventClazz) {
            this.freeflowService.saveUpdateEvent(this.procActEvent).subscribe(data => {
                this.mdlSnackbarService.showToast('保存成功！');
            });
        } else {
            this.mdlDialogService.alert('请先完善事件名称和类路径信息！');
        }
    }
    onRowSelect(event) {

    }

    /** 关闭 */
    cancel() {
        this.ref.close();
    }
}
